//
//  BaseViewController.m
//  XYMaterial
//
//  Created by 肖扬 on 15/12/9.
//  Copyright © 2015年 肖扬. All rights reserved.
//

#import "BaseViewController.h"
#import "CustomNavController.h"
@interface BaseViewController ()

@end

@implementation BaseViewController
@synthesize mainView,mainTableView,mainData,leftBtn,titleLab;
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:UIColorFromRGB(0xf3f2f2)];
    
    UIButton *btn = [UIButton buttonWithType:0];
    btn.frame = CGRectMake(20, 38.5, 7, 14);
    [btn setBackgroundImage:[UIImage imageNamed:@"箭头"] forState:UIControlStateNormal];
//    [btn addTarget: self action: @selector(goBackAction) forControlEvents: UIControlEventTouchUpInside];
    self.leftBtn = btn;
    UIBarButtonItem*back=[[UIBarButtonItem alloc]initWithCustomView:self.leftBtn];
    [self.navigationItem setHidesBackButton:YES];
    self.navigationItem.leftBarButtonItem = back;
    
    self.rightBtn = [UIButton buttonWithType:0];
    self.rightBtn.frame = CGRectMake(0, 27, 40, 30);
    [self.rightBtn setTitleColor:[UIColor whiteColor] forState:0];
    [self.rightBtn setBackgroundColor:[UIColor clearColor]];
//    [self.rightBtn setBackgroundImage:[UIImage imageNamed:@"rightButton"] forState:0];
    self.rightBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    UIBarButtonItem *rightItem=[[UIBarButtonItem alloc]initWithCustomView:self.rightBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
    
    self.titleLab = [self createLabelFrame:CGRectMake(40, 20, SWIDTH - 80, 44) title:@"" titleColor:[UIColor whiteColor] tag:0];
    [self.view addSubview:self.titleLab];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    self.mainData = [NSMutableArray array];
    UIView *tempMainView = [[UIView alloc]initWithFrame:CGRectMake(0, 64, SWIDTH, VHEIGHT)];
    [tempMainView setBackgroundColor:[UIColor clearColor]];
    self.mainView = tempMainView;
    self.mainView.backgroundColor = UIColorFromRGB(0xf3f2f2);
    [self.view addSubview:self.mainView];

    // Do any additional setup after loading the view.
}
-(void)superMainVC{
    NSLog(@"SUPER VIEW");
}
-(UITextField *)createTextField:(CGRect)frame
                   tag:(int)tag
                 color:(UIColor *)color{
    UITextField *text = [[UITextField alloc]initWithFrame:frame];
    text.tag = tag;
    text.backgroundColor = color;
    return text;
}
-(void)goBackAction{
    
    // 在这里增加返回按钮的自定义动作
    
    [self.navigationController popViewControllerAnimated:YES];
    
}
-(void)resignFirstText:(UITapGestureRecognizer *)tap{
    NSLog(@"super top");
}
//创建UILabel  tag值为三位数
- (UILabel *)createLabelFrame:(CGRect)frame
                        title:(NSString *)title
                   titleColor:(UIColor *)color
                          tag:(NSInteger)tag{
    UILabel *tempLabel = [[UILabel alloc]initWithFrame:frame];
    [tempLabel setBackgroundColor:[UIColor clearColor]];
    [tempLabel setText:title];
    [tempLabel setTag:tag];
    [tempLabel setTextColor:color];
    return tempLabel;
}
//创建UIButton tag值为四位数
- (UIButton *)createButtonFrame:(CGRect)frame
                          title:(NSString *)title
                 viewController:(id)viewController
                       selector:(SEL)selector
                            tag:(NSInteger)tag{
    UIButton *tempButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [tempButton setFrame:frame];
    [tempButton setTag:tag];
    [tempButton setBackgroundColor:[UIColor clearColor]];
    [tempButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [tempButton setTitle:title forState:UIControlStateNormal];
    [tempButton addTarget:viewController action:selector forControlEvents:UIControlEventTouchUpInside];
    return tempButton;
}
//创建UIImageView tag值为五位数
- (UIImageView *)createImageViewFrame:(CGRect)frame
                                image:(UIImage *)image
                            imageName:(NSString *)imageName
                                  tag:(NSInteger)tag{
    UIImageView *tempImageView = [[UIImageView alloc]initWithFrame:frame];
    [tempImageView setBackgroundColor:[UIColor clearColor]];
    if (image) {
        tempImageView.image = image;
    }else{
        tempImageView.image = [UIImage imageNamed:imageName];
    }
    [tempImageView setTag:tag];
    return tempImageView;
}

//创建View tag值为五位数
- (UIView *)createViewFrame:(CGRect)frame
                    bgColor:(UIColor *)color
                        tag:(NSInteger)tag{
    UIView *tempView = [[UIView alloc]initWithFrame:frame];
    [tempView setBackgroundColor:color];
    [tempView setTag:tag];
    return tempView;
}

//创建textField
- (UITextField *)createTextFieldFrame:(CGRect)frame
                              bgColor:(UIColor *)color
                                  tag:(NSInteger)tag
                         keyBoardType:(int)keyBoardType{
    UITextField *tempTextField = [[UITextField alloc]initWithFrame:frame];
    tempTextField.backgroundColor = [UIColor clearColor];
//    tempTextField.textColor = color;
    tempTextField.tag = tag;
    tempTextField.keyboardType = keyBoardType;
    tempTextField.font = [UIFont systemFontOfSize:12];
    tempTextField.textAlignment = NSTextAlignmentCenter;
    return tempTextField;
}

- (UITableView *)createTableViewFrame:(CGRect)frame
                              bgColor:(UIColor *)color
                       viewController:(id)viewController
                                  tag:(NSInteger)tag{
    UITableView *tempTableView = [[UITableView alloc]initWithFrame:frame];
    [tempTableView setBackgroundColor:color];
    [tempTableView setDelegate:viewController];
    [tempTableView setDataSource:viewController];
    tempTableView.separatorStyle = NO;
    return tempTableView;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
